package com.xgp.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 工具类，三大方法
 */
public class Demo01 {
    public static void main(String[] args) {
//        ExecutorService threadPool = Executors.newSingleThreadExecutor();    //单个线程的线程池
//        ExecutorService threadPool = Executors.newFixedThreadPool(5);    //固定的线程池的大小
        ExecutorService threadPool = Executors.newCachedThreadPool();        //可伸缩

       try{
           for(int i = 0;i < 10;i++) {
               //使用线程池去创建
               threadPool.execute(() -> {
                   System.out.println(Thread.currentThread().getName() + " OK");
               });
           }
       }catch (Exception e) {
           e.printStackTrace();
       }finally {
           //关闭线程池
           threadPool.shutdown();
       }
    }
}
